package com.googlecode.dgwt.client.dojo.reflect;

import com.googlecode.dgwt.client.dojo.core.JsMap;
import com.googlecode.dgwt.client.dojo.core.JsObject;
import com.googlecode.dgwt.client.dojo.core.NativeWrapper;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class BeanField<Bean> implements NativeWrapper {

    private String fieldName;
    private BeanMethod<Bean> getter;
    private BeanMethod<Bean> setter;
        
    public BeanField(String fieldName, BeanMethod<Bean> getter, BeanMethod<Bean> setter) {
        assert(fieldName != null);
        this.fieldName = fieldName;
        this.getter = getter;
        this.setter = setter;
    }

    public String getFieldName() {
        return fieldName;
    }

    public BeanMethod<Bean> getGetter() {
        return getter;
    }

    public BeanMethod<Bean> getSetter() {
        return setter;
    }

    @Override
    public JsObject toJavaScript() {
        JsMap<Object> map = JsMap.create();
        map.set("fieldName", getFieldName());
        map.set("getter", getGetter() == null ? null : getGetter().toJavaScript());
        map.set("setter", getSetter() == null ? null : getSetter().toJavaScript());
        return map;
    }

}
